/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package nl.hva.web.mvcwebapp.models;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
 
import javax.persistence.AssociationOverride;
import javax.persistence.AssociationOverrides;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
 
@Entity
@Table(name = "user_test")
@AssociationOverrides({
		@AssociationOverride(name = "pk.user", 
			joinColumns = @JoinColumn(name = "USER_ID")),
		@AssociationOverride(name = "pk.test", 
			joinColumns = @JoinColumn(name = "TEST_ID")) })
public class UserTest implements java.io.Serializable {
 
	private UserTestPK pk = new UserTestPK();
        private Chapter chapter;
        private int score;
        private int completed;
        
        private Set<MadeAssignment> madeassignments = new HashSet<MadeAssignment>() {
        };
        
 
	public UserTest() {
	}
 
	@EmbeddedId
	public UserTestPK getPk() {
		return pk;
	}
 
	public void setPk(UserTestPK pk) {
		this.pk = pk;
	}
 
	@Transient
	public User getUser() {
		return getPk().getUser();
	}
 
	public void setUser(User user) {
		getPk().setUser(user);
	}
 
	@Transient
	public Test getTest() {
		return getPk().getTest();
	}
 
	public void setTest(Test test) {
		getPk().setTest(test);
	}
 
 
	public boolean equals(Object o) {
		if (this == o)
			return true;
		if (o == null || getClass() != o.getClass())
			return false;
 
		CourseUser that = (CourseUser) o;
 
		if (getPk() != null ? !getPk().equals(that.getPk())
				: that.getPk() != null)
			return false;
 
		return true;
	}
 
	public int hashCode() {
		return (getPk() != null ? getPk().hashCode() : 0);
	}

    /**
     * @return the chapter
     */
    @Column(name = "chapter")
    public Chapter getChapter() {
        return chapter;
    }

    /**
     * @param chapter the chapter to set
     */
    public void setChapter(Chapter chapter) {
        this.chapter = chapter;
    }

    /**
     * @return the score
     */
    @Column(name = "score")
    public int getScore() {
        return score;
    }

    /**
     * @param score the score to set
     */
    public void setScore(int score) {
        this.score = score;
    }

    /**
     * @return the completed
     */
    @Column(name = "completed")
    public int getCompleted() {
        return completed;
    }

    /**
     * @param completed the completed to set
     */
    public void setCompleted(int completed) {
        this.completed = completed;
    }

    /**
     * @return the madeassignments
     */
    @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    public Set<MadeAssignment> getMadeassignments() {
        return madeassignments;
    }
    
    /**
     * @param madeassignments the madeassignments to set
     */
   
    public void setMadeassignments(Set<MadeAssignment> madeassignments) {
        this.madeassignments = madeassignments;
    }
    public void addMadeassignments(MadeAssignment madeassignments) {
        this.madeassignments.add(madeassignments);
    }
}